package feature

type RuntimeEnv struct {
	Develop bool `json:"develop"`
	Test    bool `json:"test"`
	Release bool `json:"release"`
}

// Feature 功能类
type Feature struct {
	Env RuntimeEnv
}

var instance *Feature

// Instance 获取配置单例
func Instance() *Feature {
	if instance == nil {
		instance = &Feature{}
	}
	return instance
}

type EnvMode uint8

const (
	EnvDevelop EnvMode = iota + 1
	EnvTest
	EnvRelease
)

var (
	env       EnvMode
	envInited bool
)

func getRuntimeEnv() EnvMode {
	ft := Instance()
	if ft.Env.Test {
		return EnvTest
	} else if ft.Env.Develop {
		return EnvDevelop
	}
	return EnvRelease
}

// 获取运行时的环境
func GetRuntimeEnv() EnvMode {
	if !envInited {
		env = getRuntimeEnv()
		envInited = true
	}
	return env
}

func IsReleaseEnv() bool {
	return GetRuntimeEnv() == EnvRelease
}

func (m EnvMode) String() string {
	switch m {
	case EnvTest:
		return "测试环境"
	case EnvDevelop:
		return "研发环境"
	default:
		return "正式环境"
	}
}
